package cn.edu.zafu.bigdata.lyq.work6;

public class ThrowsArrayIndexOutOfBoundsException {
    public static int getElement(int[] arr,int index)throws ArrayIndexOutOfBoundsException{

        return arr[index];
    }

    public static void main(String[] args) {
        int[] x={1,2,5,6,7,4};
        int y = 9;
        try{
            int z = getElement(x,y);
            System.out.println("数组中的元素为：" + z);
        }catch (ArrayIndexOutOfBoundsException e){
            System.out.println("错误：索引“"+ y +"”超出数组范围");
            System.out.println("数组长度为"+x.length);
        }
    }
}
